package concurrent.thread.volatile_1;

public class VolatileTest3 {
	public static void main(String[] args) {
		ReSortSeqDemo reSortSeqDemo = new ReSortSeqDemo();
		for (int i = 0; i < 20; i++) {
			new Thread(() -> {
				reSortSeqDemo.method01();
				reSortSeqDemo.method02();
			}).start();
		}

	}
}

class ReSortSeqDemo {
	int a = 0;
	boolean flag = false;

	public void method01() {
		a = 1;//语句1
		flag = true;//语句2
	}

	public void method02() {
		if (flag) {
			a = a + 5; //语句3
		}
		System.out.println("retValue: " + a);//可能是6或1或5或0
	}
}